package com;

import com.alibaba.simpleimage.ImageRender;
import com.alibaba.simpleimage.SimpleImageException;
import com.alibaba.simpleimage.render.ReadRender;
import com.alibaba.simpleimage.render.ScaleParameter;
import com.alibaba.simpleimage.render.ScaleRender;
import com.alibaba.simpleimage.render.WriteRender;
import com.kudian.common.utils.security.Digests;
import com.kudian.common.utils.security.Encodes;
import com.kudian.pay.HttpsUtils;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Rectangle;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by Administrator on 2016/6/4.
 */
public class Test {

    public static void main(String[] args) {
//        File in = new File("/Users/apple/IdeaProjects/out/b48c0dc73ebf44a7a43753f66f46f6b2.jpg");      //原图片
//        File out = new File("/Users/apple/IdeaProjects/out/ali_bak1_400.jpg");       //目的图片
//        // File out1 = new File("d:/desktop/d/ali_bak_50.jpg");       //目的图片
//        ScaleParameter scaleParam = new ScaleParameter(400, 400);  //将图像缩略到1024x1024以内，不足1024x1024则不做任何处理
//
//        FileInputStream inStream = null;
//        FileOutputStream outStream = null;
//        WriteRender wr = null;
//        try {
//            inStream = new FileInputStream(in);
//            outStream = new FileOutputStream(out);
//            ImageRender rr = new ReadRender(inStream);
//            ImageRender sr = new ScaleRender(rr, scaleParam);
//            wr = new WriteRender(sr, outStream);
//
//            wr.render();                            //触发图像处理
//        } catch(Exception e) {
//            e.printStackTrace();
//        } finally {
//            IOUtils.closeQuietly(inStream);         //图片文件输入输出流必须记得关闭
//            IOUtils.closeQuietly(outStream);
//            if (wr != null) {
//                try {
//                    wr.dispose();                   //释放simpleImage的内部资源
//                } catch (SimpleImageException ignore) {
//                    // skip ...
//                }
//            }
//        }

        //        sb.append("<xml>");
//        sb.append("	<appid>wxd381916cf0bbf29d</appid>");
//        sb.append("	<attach>test</attach>");
//        sb.append("	<body>APPtest</body>");
//        sb.append("	<mch_id>1339045001</mch_id>");
//        sb.append("	<nonce_str>65c8fac043994edd8fcdad587c8dc6c1</nonce_str>");
//        sb.append("	<notify_url>http://101.201.74.2/pay/wxback</notify_url>");
//        sb.append("	<out_trade_no>20160619000006</out_trade_no>");
//        sb.append("	<total_fee>1</total_fee>");
//        sb.append("	<trade_type>APP</trade_type>");
//        sb.append("	<sign>7902E3B64F9CC12F44756A2EC774A350</sign>");
//        sb.append("</xml>");
//        StringBuffer sb = new StringBuffer();
//
//        sb.append("<xml>\t<appid>wxd381916cf0bbf29d</appid>\t<attach><![CDATA[jisuan]]></attach>\t<body><![CDATA[酷点帮帮]]></body>\t<detail><![CDATA[]]></detail>\t<mch_id>1339045001</mch_id>\t<nonce_str>e145bfa1d82e43b4b8e6679d2a01abcf</nonce_str>\t<notify_url>http://101.201.74.2/pay/wxback</notify_url>\t<out_trade_no>fb0eec5306e847a7aa982713f9adf74f</out_trade_no>\t<total_fee>0</total_fee>\t<trade_type>APP</trade_type>\t<sign>3634ACAB768401E6819F08FF1A9EFB49</sign></xml>");
//
//        // 本地起的https服务
//        String httpsUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder";

//        // 移动设备经纬度
//        double lon = 116.312528, lat = 39.983733;
//        // 千米
//        int radius = 5;
        SpatialContext geo = SpatialContext.GEO;
//        Rectangle rectangle = geo.getDistCalc().calcBoxByDistFromPt(
//                geo.makePoint(lon, lat), radius * DistanceUtils.KM_TO_DEG, geo, null);
//        System.out.println(rectangle.getMinX() + "-" + rectangle.getMaxX());// 经度范围
//        System.out.println(rectangle.getMinY() + "-" + rectangle.getMaxY());// 纬度范围
//
        // 移动设备经纬度
        double lon1 = 117.19250442422475, lat1 = 39.128286001859834;
        // 商户经纬度
        // double lon2 = 116.312528, lat2 = 39.983733;
        double lon2 = 117.19250442422475, lat2 = 39.128286001859834;

        geo = SpatialContext.GEO;
        double distance = geo.calcDistance(geo.makePoint(lon1, lat1), geo.makePoint(lon2, lat2)) * DistanceUtils.DEG_TO_KM;
        System.out.println(distance * 1000);// KM

//        System.out.println(encrypt("zy15620714103"));
//        System.out.println(encrypt("3"));
//        System.out.println(encrypt("123456"));
//        System.out.println(encrypt("1"));
//        System.out.println(encrypt("54321"));
//        System.out.println(encrypt("123456"));
//        System.out.println(encrypt("123456"));
//        System.out.println(encrypt("88888888"));
//        System.out.println(encrypt("222"));
//        System.out.println(encrypt("88888888"));
//        System.out.println(encrypt("123456"));
//        System.out.println(encrypt("1"));
//        System.out.println(encrypt("222222"));
//        System.out.println(encrypt("1"));
//        System.out.println(encrypt("123456789"));
//        System.out.println(encrypt("123456"));
    }

    public static String encrypt(String password) {
        System.out.println(password);
        return Encodes.encodeHex(Digests.sha1(password.getBytes(), Encodes.decodeHex("3d06a5c14d010804"), 1024));
    }
}
